package Chess.Pieces;

import java.awt.Color;
import Chess.*;

/**
 *	An abstract class representing a generic Piece in Chess.
 *
 *	@author		Jeff Chan, James Kuo
 */
public abstract class Piece {
	private int moveCount = 0;
	private Color color;
	
	public enum PieceType {
		PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING
	}
	
	public Piece(Color color) {
		if (color == Color.WHITE || color == Color.BLACK)
			this.color = color;
		else
			this.color = Color.WHITE;
	}
	
	public Color getColor() {
		return color;
	}
	
	public abstract PieceType getPieceType();
	public abstract boolean canAttack(Board board, Square currentSquare, Square occupiedSquare);
	public abstract boolean canMove(Board board, Square currentSquare, Square emptySquare);
	
	public String getImage() {
		if(color == Color.WHITE)
			return this.getClass().getSimpleName()+"White.png";
		else
			return this.getClass().getSimpleName()+"Black.png";
	}
        
	public boolean isFirstMove() {
		return moveCount == 0;
	}
	
	public int getMoveCount() {
		return moveCount;
	}
	
	public void incrementMoveCount() {
		moveCount += 1;
	}
	
	public void decrementMoveCount() {
		moveCount -= 1;
	}
	
	protected boolean validSetupForMove(Board board, Square currentSquare, Square emptySquare) {
		return (this == board.getPiece(currentSquare) && !board.hasPiece(emptySquare));
	}
	
	protected boolean validSetupForAttack(Board board, Square currentSquare, Square occupiedSquare) {
		return (this == board.getPiece(currentSquare) &&
				board.hasPiece(occupiedSquare) && 
				!this.getColor().equals(board.getPiece(occupiedSquare).getColor()));
	}
}